package com.auth.sdk.transmit;

import com.auth.sdk.LoginInfo;
import org.apache.logging.log4j.util.Strings;

import java.util.Collections;
import java.util.List;

/**
 * Login context holder
 *
 * @description:  登录态属性
 * @author: cyj
 * @date 2021 -12-23 10:36:58
 *
 *
 */
public final class LoginContextHolder {

    public static LoginInfo getLoginInfo() {
        return LoginContext.LOGIN_INFO.get();
    }

    protected static void setLoginInfo(LoginInfo loginInfo) {
        LoginContext.LOGIN_INFO.set(loginInfo);
    }

    protected static void removeLoginInfo() {
        LoginContext.LOGIN_INFO.remove();
    }

    public static String getLoginName() {
        LoginInfo loginInfo = LoginContext.LOGIN_INFO.get();
        if (null != loginInfo) {
            return loginInfo.getUserName();
        }
        return Strings.EMPTY;
    }

    public static String getLoginId() {
        LoginInfo loginInfo = LoginContext.LOGIN_INFO.get();
        if (null != loginInfo) {
            return loginInfo.getUserId();
        }
        return Strings.EMPTY;
    }

    public static List<Object> getLoginRoles() {
        LoginInfo loginInfo = LoginContext.LOGIN_INFO.get();
        if (null != loginInfo) {
            return loginInfo.getRoles();
        }
        return Collections.EMPTY_LIST;
    }

    public static List<Object> getLoginAuths() {
        LoginInfo loginInfo = LoginContext.LOGIN_INFO.get();
        if (null != loginInfo) {
            return loginInfo.getAuths();
        }
        return Collections.EMPTY_LIST;
    }
}
